package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.Tenement;
import com.ruoyi.system.service.ITenementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 诸侯管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-19
 */
@RestController
@RequestMapping("/tenement")
public class TenementController extends BaseController
{
    @Autowired
    private ITenementService tenementService;

    /**
     * 查询诸侯管理列表
     */
    @RequiresPermissions("info:tenement:list")
    @GetMapping("/list")
    public TableDataInfo list(Tenement tenement)
    {
        startPage();
        List<Tenement> list = tenementService.selectTenementList(tenement);
        return getDataTable(list);
    }

    /**
     * 导出诸侯管理列表
     */
    @RequiresPermissions("info:tenement:export")
    @Log(title = "诸侯管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tenement tenement)
    {
        List<Tenement> list = tenementService.selectTenementList(tenement);
        ExcelUtil<Tenement> util = new ExcelUtil<Tenement>(Tenement.class);
        util.exportExcel(response, list, "诸侯管理数据");
    }

    /**
     * 获取诸侯管理详细信息
     */
    @RequiresPermissions("info:tenement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tenementService.selectTenementById(id));
    }

    /**
     * 新增诸侯管理
     */
    @RequiresPermissions("info:tenement:add")
    @Log(title = "诸侯管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tenement tenement)
    {
        return toAjax(tenementService.insertTenement(tenement));
    }

    /**
     * 修改诸侯管理
     */
    @RequiresPermissions("info:tenement:edit")
    @Log(title = "诸侯管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tenement tenement)
    {
        return toAjax(tenementService.updateTenement(tenement));
    }

    /**
     * 删除诸侯管理
     */
    @RequiresPermissions("info:tenement:remove")
    @Log(title = "诸侯管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tenementService.deleteTenementByIds(ids));
    }

    @GetMapping(value = "/count/{id}")
    public AjaxResult getCount(@PathVariable("id") Long id)
    {
        return success(tenementService.getCount(id));
    }

    @GetMapping(value = "/getTenesByRidId/{Ridid}")
    public AjaxResult getTenesByRidId(@PathVariable("Ridid") Long Ridid)
    {
        return success(tenementService.getTenesByRidId(Ridid));
    }

    @GetMapping("/qrcoude/{userId}")
    public AjaxResult qrcoude(@PathVariable("userId") Long userId)
    {

        return success(tenementService.qrcoude(userId));
    }
}
